package info.douyi.dps.serviceImpl;

import info.douyi.dps.mapper.PreviewImgMapper;
import info.douyi.dps.model.PreviewImg;
import info.douyi.dps.model.PreviewImgExample;
import info.douyi.dps.service.PreviewImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class PreviewImgServiceImpl implements PreviewImgService {

    @Autowired
    private PreviewImgMapper previewImgMapper;

    @Override
    public List<String> getImgListByPestId(Integer id) {
        PreviewImgExample example = new PreviewImgExample();
        example.createCriteria().andPidEqualTo(id);
        List<PreviewImg> list = previewImgMapper.selectByExample(example);
        return list.stream()
                .map(PreviewImg::getImgurl)
                .toList();
    }

    @Override
    public int addImage(PreviewImg previewImg) {
        previewImgMapper.insert(previewImg);
        return 0;
    }
}
